<?php  
    require_once('inc/conn.php');
    $total_num=mysql_num_rows(mysql_query("SELECT * FROM slide"));
    $pagesize=5;
    $page_num=ceil($total_num/$pagesize);

    $page=@$_GET['page'];
    if($page<1||$page=""){
        $page=1;
    }
    if($page>$page_num){
        $page=$page_num;
    }
    $offset=$pagesize*($page-1);
    $prepage=($page<>1)?$page-1:$page;
    $nextpage=($page<>$page_num)?$page+1:$page;
    $result=mysql_query("SELECT * FROM slide ORDER BY id desc LIMIT $offset,$pagesize");
 ?>
 <!doctype html>
 <html lang="en">
 <head>
     <meta charset="UTF-8">
     <title>Document</title>
     <script type="text/javascript">
function AutoResizeImage(maxWidth,maxHeight,objImg){
var img = new Image();
img.src = objImg.src;
var hRatio;
var wRatio;
var Ratio = 1;
var w = img.width;
var h = img.height;
wRatio = maxWidth / w;
hRatio = maxHeight / h;
if (maxWidth ==0 && maxHeight==0){
Ratio = 1;
}else if (maxWidth==0){//
if (hRatio<1) Ratio = hRatio;
}else if (maxHeight==0){
if (wRatio<1) Ratio = wRatio;
}else if (wRatio<1 || hRatio<1){
Ratio = (wRatio<=hRatio?wRatio:hRatio);
}
if (Ratio<1){
w = w * Ratio;
h = h * Ratio;
}
objImg.height = h;
objImg.width = w;
}
</script>
 </head>
 <body>
     <table width="80%" border="1" cellpadding="0" cellspacing="0">
         <tr><td colspan="4">焦点幻灯片列表</td></tr>
         <tr><td>标题</td><td>链接</td><td>缩略图</td><td>操作</td></tr>
         <tr>
         <?php 
            if($total_num>0){
                while($row=mysql_fetch_array($result)){
                    ?>
                
                    <td><?php echo $row['title']; ?></td>

                    <td><?php if($row['lianjie']==""){ echo "无";}else{ ?> <a target="new" href="<?php echo $row['lianjie'];?>">查看</a> <?php } ?>
                    </td>

                    <td align="center"><img src="<?php echo $row['tupian']?>" onload="AutoResizeImage(60,80,this)" alt=""></td>
                    <td><input type="submit" value="修改" onclick="window.location.href='slide_modify.php?id=<?php echo $row['id']?>'">&nbsp;&nbsp;<input type="button" value="删除" onclick="window.location.href='slide_delete.php?id=<?php echo $row['id']?>'"></td>
                </tr>      
                <?php
            }
            
            }else{
                ?>
                <tr><td align="center">暂无记录！</td></tr>
                <?php
            }
         ?>
         <tr><td colspan="4" align="center"><?php echo $page ?>/<?php echo $page_num ?>&nbsp;&nbsp;<a href="?page=1">首页</a>&nbsp;&nbsp;<a href="?page=<?php echo $prepage;?>">上一页</a>&nbsp;&nbsp;<a href="?page=<?php echo $nextpage;?>">下一页</a>&nbsp;&nbsp;<a href="?page=<?php echo $page_num;?>">尾页</a></td></tr>
            
         
     </table>
 </body>
 </html>